import { Tree,Icon,Progress } from 'antd';
const TreeNode = Tree.TreeNode;

class Main extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        const {details} = this.props;
        let deKeys = new Array();
        let tns = new Array();
        let m = 0;
        for(let i=0;i<details.length;i++) {
            const data = details[i];
            if(data.fid=="0") {
                let tnsInner = new Array();
                let n = 0;
                for(let j=0;j<details.length;j++) {
                    const dataInner = details[j];
                    if(dataInner.fid==data.id) {
                        tnsInner.push(<TreeNode 
                            title={<div>
                                    <Icon type="file-text" /> 
                                    {dataInner.chname} 
                                    [{dataInner.initcount+"/"+dataInner.count}]
                                   </div>} key={"0-0-"+m+"-"+n++} isLeaf />);
                    }
                }
                if(tnsInner.length>0)
                    tns.push(<TreeNode title={<div>
                        <Icon type="file" /> {data.chname}
                        <Progress style={{"marginLeft":"5px",width:"120px"}} percent={(data.count=="0"||data.initcount>data.count)?0:(data.initcount*100/data.count)} strokeWidth={5} status="active" />
                        </div>} key={"0-0-"+m}>{tnsInner}</TreeNode>);
                else
                    tns.push(<TreeNode title={<div>
                        <Icon type="file" /> {data.chname} 
                        <Progress style={{"marginLeft":"5px",width:"120px"}} percent={(data.count=="0"||data.initcount>data.count)?0:(data.initcount*100/data.count)} strokeWidth={5} status="active" />
                        </div>} key={"0-0-"+m} />);
                deKeys.push("0-0-"+(m++));
            }
        }
        //console.log("defaultExpandedKeys:",deKeys);
        return (
            <Tree className="myCls" showLine expandedKeys={deKeys} defaultExpandAll >
                <TreeNode title={<div><Icon type="file" /> 数据 [初始数/总数]</div>} key={"0-0"}>
                    {tns}
                </TreeNode>
            </Tree>
        );
    }
}

export default Main


// <TreeNode title="parent 1" key="0-0">
//                     <TreeNode title="parent 1-0" key="0-0-0" disabled>
//                         <TreeNode title="leaf" key="0-0-0-0" disableCheckbox />
//                         <TreeNode title="leaf" key="0-0-0-1" />
//                     </TreeNode>
//                     <TreeNode title="parent 1-1" key="0-0-1">
//                         <TreeNode title={<span style={{ color: '#08c' }}>sss</span>} key="0-0-1-0" />
//                     </TreeNode>
//                 </TreeNode>